package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: qian
 * Date: 2022-12-28
 * Time: 15:04
 */
class MyThread extends Thread{
    @Override
    public void run() {
        //线程里要执行的操作
        while (true){
            System.out.println("hello thread!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
public class Demo1 {
    public static void main(String[] args) throws InterruptedException {
        MyThread t=new MyThread();
        //调用start方法时才会创建新的线程，然后执行run里面的逻辑，等run里面的代码执行完成，新的线程就运行结束
        t.start();
        while(true){
            System.out.println("hello main");
            Thread.sleep(1000);
        }
    }
}
